<!--{include file='public/top' /}-->

<body>
<div class="x-body">
    <form class="layui-form" autocomplete="off">
        <div class="layui-form-item">
            <div class="layui-form-item">
                <label  class="layui-form-label"> <span class="x-red">*</span>标题 </label>
                <div class="layui-input-block">
                    <input type="text" name="title" lay-verify="required" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label  class="layui-form-label"> <span class="x-red">*</span>关键词 </label>
                <div class="layui-input-block">
                    <input type="text" name="keyword" lay-verify="required" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label  class="layui-form-label"> <span class="x-red">*</span>描述 </label>
                <div class="layui-input-block">
                    <input type="text" name="description" lay-verify="required" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" style="margin: 20px 0 0 0;"> <span class="x-red">*</span>封面</label>
                <label for="cover"> <span id="imgg1"> <img style="height: 80px;width: 120px;margin: 0 10px 0 0;cursor:pointer;" src="/static/admin/img/addLogo_box.png"> </span> <span>请按照要求的尺寸添加</span> </label>
                <button type="button" class="layui-btn layui-btn-small layui-hide" id="cover"> <i class="layui-icon">&#xe67c;</i>上传图片 </button>
            </div>
            
            
            <div class="layui-form-item">
                <label class="layui-form-label" style="margin: 20px 0 0 0;"> <span class="x-red"></span>多图</label>
                <span id="delmultimg">
                    
                </span>
                <label for="multimg"><img style="width: 120px;margin: 0 10px 0 0;cursor:pointer;" src="/static/admin/img/addLogo_box.png"><span>请按照要求的尺寸添加</span> </label>
                <button type="button" class="layui-btn layui-btn-small layui-hide" id="multimg"> <i class="layui-icon">&#xe67c;</i>上传图片 </button>
            </div>
            
            <div class="layui-form-item"> <span class="x-red">*</span>内容 
                <script type="text/plain" id="editor" class="ueueueue"></script>
                <div class="con-split" style="height: 100px;"></div>
            </div>
            <br>
        </div>
        <div class="layui-form-item">
            <input type="hidden" name="lanmuid" value="<!--{$Request.get.lanmuid}-->" />
            <button type="button"  class="layui-btn layui-btn-normal" lay-filter="add" lay-submit="">提交</button>
        </div>
    </form>
</div>
<script>
    var addurl = '/admin/newslist/add.html';
    var uploadurl = '/admin/newslist/upload.html';
    var zipupUrl = '/admin/index/zipUp';
    var ue = UE.getEditor('editor');
    //编辑器
    layui.use('laydate', function(){
      var laydate = layui.laydate;
      
      //执行一个laydate实例
      laydate.render({
        elem: '#create_time' //指定元素
        ,type:'datetime'
      });
    });
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer;

        //自定义验证规则
        form.verify({
            pass: [/(.+){6,12}$/, '密码必须6到12位']
            ,repass: function(value){
                if($('#L_pass').val()!=$('#L_repass').val()){
                    return '两次密码不一致';
                }
            }
        });
        //监听提交
        form.on('submit(add)', function(data){
            $.post(addurl, data.field,function(res) {
                if(res.code===200){
                    layer.msg(res.msg, {
                        time: 1000, //不自动关闭
                        icon:6,
                        end:function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }
                    });
                    return false;
                }else {
                    layer.msg(res.msg)
                }


            });

        });
    });
    
    layui.use(['upload','layer'], function(){
        var upload = layui.upload;
        var layer = layui.layer;
        //执行实例
        var uploadInst = upload.render({
            elem: '#cover',
            url: uploadurl,
            auto: false,
            accept: 'images',
            acceptMime: 'image/*',
            size : '100',
            multiple: false,
            choose: function(o){
                layer.prompt({
                    formType: 3,
                    value: '附件',
                    title: '请输入附件描述'
                }, function(value, index, elem){
                    uploadInst.config.data = {
                        subject:value
                    }
                    layer.close(index);
                    uploadInst.upload();
                });
            },
            done: function(res){
                var  option = '<img style="height: 80px;width: 120px;margin: 0 10px 0 0;cursor:pointer;" src="'+res.data.path+'">';
                $('#imgg1').html(option);
                var addBox = '<input type="hidden" name="cover" value="'+res.data.id+'">';
                document.getElementById('t1').innerHTML += addBox;
            },
            error: function(){
                
            }
            
        });
        
        var uploadInst = upload.render({
            elem: '#multimg',
            url: uploadurl,
            auto: false,
            accept: 'images',
            acceptMime: 'image/*',
            size : '100',
            multiple: false,
            choose: function(o){
                layer.prompt({
                    formType: 3,
                    value: '附件',
                    title: '请输入附件描述'
                }, function(value, index, elem){
                    uploadInst.config.data = {
                        subject:value
                    }
                    layer.close(index);
                    uploadInst.upload();
                });
            },
            done: function(res){
                var  option = '<span><img src="'+res.data.path+'" width="120"><!--i class="layui-icon layui-icon-delete" style="display: inline-block"></i--><input type="hidden" name="multimg[]" value="'+res.data.id+'"></span>';
                $('#delmultimg').append(option);
            },
            error: function(){
                
            }
            
        });
    });    
</script>
</body>
</html>